package control;

import database.Database;
import java.sql.SQLException;
import model.ProductFamily;

/**
 * Denne klasses opgave er at manipulere i databasen i forbindelse med varegruppe
 * @author Sonny Sandberg
 */
public abstract class ProductFamilyControl 
{
    /**
     * Tilføj/Redigér varegruppe
     * @param ProductFamily
     * @return int
     * @throws ClassNotFoundException
     * @throws SQLException 
     */
    public static int addAlterProductFamily(ProductFamily productFamily) throws ClassNotFoundException, SQLException
    {
        Database db = new Database();
        
        int handled = 0;
        // Hvis varegruppen har et ID, så opdater den
        if (productFamily.getId() > 0)
        {
            handled = db.manipulateDB("UPDATE bs_product_family SET name = '"+productFamily.getName()+"' WHERE id = '"+productFamily.getId()+"'");
        }
        // Ellers tilføj den
        else
        {
            handled = db.manipulateDB("INSERT INTO bs_product_family (name) VALUES ('"+productFamily.getName()+"')");
        }
        db.closeDB();
        
        return handled;
    }
}